package com.zoro.barn.business.service.pp.conf;

import com.zoro.barn.business.service.pp.server.DocumentSqlTestService;
import com.zoro.barn.commons.db.autopage.AutoPageConfig;
import com.zoro.barn.commons.redis.cache.RedisManagerConfig;
import com.zoro.barn.commons.webcommons.webconfig.AllWebConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

/**
 * @author zhaoxingwu
 */
@Import({ AllWebConfig.class,AutoPageConfig.class, RedisManagerConfig.class})
@Configuration
public class CommonConfig {


    @Bean
    public DocumentSqlTestService documentSqlTestService() {
        RestClient restClient = RestClient.builder()
                .baseUrl("http://localhost:19002")
                .messageConverters(v -> {
                    // TODO 这里要加一个自定义解析器，类似 Feign 的decoder , 否则 分页的功能（PageResultInfoInterface）会报错
                })
                .build();
        RestClientAdapter adapter = RestClientAdapter.create(restClient);
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
        return factory.createClient(DocumentSqlTestService.class);
    }
}
